package com.base.balibrary.utils.ESManager;


import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * BAndroid
 * 简单管理分配所需要的线程池
 * Created by YichenZ on 2015/8/25 17:06.
 */
public class ExecutorServiceManager{

    private static Object object =new Object();
    private static ExecutorServiceManager instance;

    private static final Integer MAX_EXECUTOR_SERVICE=3;

    private static ExecutorService mainExecutorService;

    private ExecutorServiceManager(){
        init();
    }

    public static ExecutorServiceManager getInstance(){
        if(instance==null){
            synchronized (object){
                if(instance==null){
                    instance=new ExecutorServiceManager();
                }
            }
        }
        return instance;
    }

    private void init(){
        mainExecutorService= newFixedThreadPool();
    }

    public ExecutorService newFixedThreadPool() {
        return new ThreadPoolExecutor(MAX_EXECUTOR_SERVICE, MAX_EXECUTOR_SERVICE,
                10L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<Runnable>());
    }
}
